﻿using System;
using System.Windows.Forms.Integration;
using System.Windows.Forms;
namespace UWCSE.CompleterVSPackage
{
    partial class EnterQueryForm : IDisposable
    {
        private readonly Action cancelQuery;
        private readonly ElementHost host;

        public EnterQueryForm(Action<string> executeQuery, Action cancelQuery, string initialQuery = "")
            : this()
        {
            this.SuspendLayout();
            Action closeWindow = () => this.Hide();
            this.cancelQuery = closeWindow + cancelQuery;
            
            EnterQueryControl eqc = new EnterQueryControl((str) =>
            {
                closeWindow();
                executeQuery(str);
            }, this.cancelQuery, initialQuery);
                   
            this.Controls.Clear();
            host = new ElementHost();
            host.Dock = DockStyle.Fill;
            host.Child = eqc;
            this.Controls.Add(host);
            this.ResumeLayout(false);
        }

        private void EnterQueryForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            this.cancelQuery();
        }

        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
                host.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.SuspendLayout();
            // 
            // EnterQueryForm
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(494, 262);
            this.Name = "EnterQueryForm";
            this.Text = "Enter Query";
            this.ResumeLayout(false);

        }

        #endregion
    }
}